package com.china08.yxyapi.api.manage.edu.office.outernotice;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.mg.office.YxyNoticeOutter;
import com.china08.yxyapi.entity.mg.office.YxyNoticeOutter.YxyNotifictionSchool;
import com.china08.yxyapi.model.YxyApiPageReqModel;
import com.china08.yxyapi.repository.mg.YxyNoticeOutterRepository;

@CrossOrigin
@RestController
public class OuterNoticeReceiveNoReadCountControlelr extends YxyApiBaseController {

    @Autowired
    YxyNoticeOutterRepository yxyNoticeOutterRepository;

    @ResponseBody
    @RequestMapping(value = "/api_yw/manage/edu/office/outerNotice/receive/noread/count", method = RequestMethod.POST)
    public RespModel precess(HttpServletRequest request, HttpServletResponse response, @RequestBody ReqModel reqModel) {
        // 当前教育局id
        String edbId = getProfile(request, response).getSchoolId();
        // 未删除状态
        int isDelete = 0;

        Integer count = 0;

        List<YxyNoticeOutter> list = yxyNoticeOutterRepository.findByReceiveSchoolSchoolIdAndReceiveSchoolIsDelete(edbId, isDelete);
        for (YxyNoticeOutter outer : list) {
            List<YxyNotifictionSchool> schoolList = outer.getReceiveSchool();
            for (YxyNotifictionSchool school : schoolList) {
                String schoolId = school.getSchoolId();
                Integer isRead = school.getIsRead();
                if (edbId.equals(schoolId) && isRead == 0) {
                    count = count + 1;
                }
            }
        }

        RespModel respModel = new RespModel();
        respModel.noReadCount = count;
        return respModel;
    }

    protected static class ReqModel extends YxyApiPageReqModel {

    }

    protected static class RespModel {
        public Integer noReadCount;
    }
}
